import pandas as pd
df_all=pd.read_csv(r'D:\py\pythonProject\population-data\data\originalData\分省家庭总户数数据.csv',skiprows=3,encoding="gbk")
df_all=df_all.iloc[:-2]
df_1  =pd.read_csv(r'D:\py\pythonProject\population-data\data\originalData\分省一户家庭数据.csv', skiprows=3,encoding="gbk")
df_1=df_1.iloc[:-2]
df_2  =pd.read_csv(r'D:\py\pythonProject\population-data\data\originalData\分省两户家庭数据.csv', skiprows=3,encoding="gbk")
df_2=df_2.iloc[:-2]
df_3  =pd.read_csv(r'D:\py\pythonProject\population-data\data\originalData\分省三户家庭数据.csv', skiprows=3,encoding="gbk")
df_3=df_3.iloc[:-2]
df_m  =pd.read_csv(r'D:\py\pythonProject\population-data\data\originalData\分省多户家庭数据.csv', skiprows=3,encoding="gbk")
df_m=df_m.iloc[:-2]

print(df_m.iloc[:,1:])
df_m.iloc[:,1:] = df_all.iloc[:,1:]-df_1.iloc[:,1:]-df_2.iloc[:,1:]-df_3.iloc[:,1:]
print(df_m.iloc[:,1:])

df_1.iloc[:,1:] = df_1.iloc[:,1:]/df_all.iloc[:,1:]
df_1.iloc[:, 1:] = df_1.iloc[:, 1:].applymap(lambda x: round(x * 100, 2))
print(df_1.iloc[:,1:])
df_1.to_csv(r"D:\py\pythonProject\population-data\data\temp\一户家庭结构.csv",encoding="gbk")
df_2.iloc[:,1:] = df_2.iloc[:,1:]/df_all.iloc[:,1:]
df_2.iloc[:, 1:] = df_2.iloc[:, 1:].applymap(lambda x: round(x * 100, 2))
df_2.to_csv(r"D:\py\pythonProject\population-data\data\temp\两户家庭结构.csv",encoding="gbk")
df_3.iloc[:,1:] = df_3.iloc[:,1:]/df_all.iloc[:,1:]
df_3.iloc[:, 1:] = df_3.iloc[:, 1:].applymap(lambda x: round(x * 100, 2))
df_3.to_csv(r"D:\py\pythonProject\population-data\data\temp\三户家庭结构.csv",encoding="gbk")
df_m.iloc[:,1:] = df_m.iloc[:,1:]/df_all.iloc[:,1:]
df_m.iloc[:, 1:] = df_m.iloc[:, 1:].applymap(lambda x: round(x * 100, 2))
df_m.to_csv(r"D:\py\pythonProject\population-data\data\temp\多户家庭结构.csv",encoding="gbk")